function actionGetMe() {
    var token = Lib.getCookie('access_token');
    if(token == '') {
        return true;
    }
    var callback = function(xmlhttp) {
        var user = JSON.parse(xmlhttp.responseText);
        var span = document.getElementById('username');
        while( span.firstChild ) {
            span.removeChild( span.firstChild );
        }
        span.appendChild( document.createTextNode(user.name) );
        var span = document.getElementById('uploaded');
        while( span.firstChild ) {
            span.removeChild( span.firstChild );
        }
        span.appendChild( document.createTextNode(formatFileSize(user.uploaded)) );
        var span = document.getElementById('downloaded');
        while( span.firstChild ) {
            span.removeChild( span.firstChild );
        }
        span.appendChild( document.createTextNode(formatFileSize(user.downloaded)) );
    }
    var a = Lib.http('get', '/api/me', {'access_token' : token}, callback, true);
    return true;
}
function formatFileSize(byte_size)
{
    if(parseInt(byte_size) > 1073741824) {
        return (byte_size/1073741824).toFixed(1) + 'GiB';
    }
    if(parseInt(byte_size) > 1048576) {
        return parseInt(byte_size/1048576) + 'MiB';
    }
    return parseInt(byte_size/1024) + 'KiB';
}
function attachEventDisplayLoginOrLogout() {
    var token = Lib.getCookie('access_token');
    if(token == '') {
        document.getElementById('logout').style.display = 'none';
        document.getElementById('login').style.display = 'block';
    } else {
        actionGetMe();
        document.getElementById('login').style.display = 'none';
        document.getElementById('logout').style.display = 'block';
    }
}
